﻿using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL;
using MOD;

namespace BLL
{
    public class B_Che
    {
        private int iDataConn = DataBase.IN_S2;
        public DataTable SelectZuChe(int iYongHuId, Int32 iServerType)
        {
            DataBase dDb = new DataBase();
            StringBuilder sCmdText = new StringBuilder();
            iDataConn = iServerType;

            sCmdText.Append("select b.id,b.chePaiHaoMa from YongHuZuGuanXi a,Che b ");
            sCmdText.Append("Where ");
            sCmdText.Append(" a.yonghuid = @YongHuId and a.zuid = b.zuid ");
         
            SqlParameter[] sSp = {
                                   new SqlParameter("@YongHuId",SqlDbType.Int)
                                 };

            sSp[0].Value = iYongHuId;
           
            return dDb.GetDataTable(sCmdText.ToString(), iDataConn, sSp);
        }
        public DataTable SelectChe(M_Che mCe, Int32 iServerType)
        {
            DataBase dDb = new DataBase();
            StringBuilder sCmdText = new StringBuilder();
            iDataConn = iServerType;

            sCmdText.Append("select id,chePaiHaoMa from Che ");
            sCmdText.Append("Where ");
            sCmdText.Append("id = @id");

            SqlParameter[] sSp = {
                                   new SqlParameter("@id",SqlDbType.Int)
                                 };

            sSp[0].Value = mCe.Id;

            return dDb.GetDataTable(sCmdText.ToString(), iDataConn, sSp);
        }
        public DataTable UserLogin(String sUserName, String sPassWord, Int32 iServerType)
        {
            DataBase dDb = new DataBase();
            StringBuilder sCmdText = new StringBuilder();
            iDataConn = iServerType;

            sCmdText.Append("Select a.id,a.ChePaiHaoMa,c.id as UserId,c.DengLuMing,c.MiMa from Che a,YongHuZuGuanXi b,YongHu c ");
            sCmdText.Append("Where ");
            sCmdText.Append("(a.ChePaiHaoMa = @ChePaiHaoMa or a.CheZaiShouJiHao = @CheZaiShouJiHao) ");
            sCmdText.Append("and ");
            sCmdText.Append("RIGHT(RTRIM(a.CheZaiShouJiHao),4) = @PassWord ");
            sCmdText.Append("and ");
            sCmdText.Append("a.ZuId = b.ZuId ");
            sCmdText.Append("and ");
            sCmdText.Append("b.YongHuId = c.id ");

            SqlParameter[] sSp = {
                                   new SqlParameter("@ChePaiHaoMa",SqlDbType.Char),
                                   new SqlParameter("@CheZaiShouJiHao",SqlDbType.Char),
                                   new SqlParameter("@PassWord",SqlDbType.Char)
                                 };

            sSp[0].Value = sUserName;
            sSp[1].Value = sUserName;
            sSp[2].Value = sPassWord;

            return dDb.GetDataTable(sCmdText.ToString(), iDataConn, sSp);
        }
    }
}
